package bb.lanxing.activity.base;

import bb.lanxing.calc.data.DisplayPoint;
import bb.lanxing.manager.RemoteServiceManager;
import bb.lanxing.util.Log;

public abstract class BaseDisplayActivity extends BaseActivity {
    private final static String TAG = "BaseDisplayActivity";

    private RemoteServiceManager.DisplayPointChangedListener displayPointChangedListener = displayPoint -> {
        Log.v(TAG, "[BaseDisplayActivity] displayPoint = " + displayPoint);
        if (displayPoint != null) {
            Log.v(TAG, "[BaseDisplayActivity] displayPoint.getCadence() = " + displayPoint.getCadence()
                    + ", displayPoint.getHeartrate() = " + displayPoint.getHeartrate());
            runOnUiThread(() -> onRefreshUI(displayPoint));
        }
    };

    protected abstract void onRefreshUI(DisplayPoint displayPoint);

    @Override
    public void onResume() {
        super.onResume();
        RemoteServiceManager.getInstance().registerDisplayPointChangedListener(displayPointChangedListener);
    }

    @Override
    public void onPause() {
        super.onPause();
        RemoteServiceManager.getInstance().unregisterDisplayPointChangedListener(displayPointChangedListener);
    }
}